package Controls;

import Core.ALIGN;
import Core.ControlImage;
import Core.LayoutManager;

public class CheckBox extends LayoutManager
{
	private Button check;
	private Text capt;
	private boolean checked = false;

	private static ControlImage pick = new ControlImage("/pick.png", ALIGN.CENTER, 1, -3);

	public CheckBox(String text, int w)
	{
		super(w, 0);
		caption = text;
		type = HORIZONTAL;
		v_border = 3;
		allowToEnlarge = true;
		spacing = 4;

		check = new Button(" ", 16, 16);
		capt = new Text(caption, getAvailableW() - check.getW() - spacing, true);

		addControl(check);
		addControl(capt);
	}

	public void setCheck(boolean c)
	{
		if(c && !checked)
		{
			check.addImage(pick);
			checked = c;
			return;
		}

		if(!c && checked)
		{
			check.removeAllImages();
			checked = c;
			return;
		}
	}

	public boolean getChecked()
	{
		return checked;
	}

	public void press()
	{
		super.press();
		
		setCheck(!checked);
	}
}
